package Prototype;

import javax.swing.*;
import java.awt.*;

class Sunwukong extends JPanel implements Cloneable{
    private static final long serialVersionUID = 5543049531872119328L;
    public Sunwukong(){
        JLabel ll = new JLabel(new ImageIcon("src/Wukong.jpg"));
        this.add(ll);
    }
    //clone
    public Object clone(){
        Sunwukong w = null;
        try {
            w = (Sunwukong)super.clone();
        }catch (CloneNotSupportedException e){
            e.printStackTrace();
        }
        return w;
    }
}
public class PrototypeWukong {
    public static void main(String[] args) {
        JFrame jf = new JFrame("原型模式测试");
        jf.setLayout(new GridLayout(1,2));
        Container container = jf.getContentPane();
        Sunwukong s1 = new Sunwukong();
        container.add(s1);
        Sunwukong s2 = (Sunwukong)s1.clone();
        container.add(s2);
        jf.pack();
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
